<?php
	function imageupload($edit='insert',$folder){
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();// 实例化上传类
		//$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->saveRule='guid';
		$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->savePath =  'Public/Uploads/'.$folder."/".date('Ymd',time()).'/';// 设置附件上传目录
		if(!is_dir('Public/Uploads/'.$folder)){
			mkdir('Public/Uploads/'.$folder);
		}
		if(!is_dir($upload->savePath )){
			mkdir($upload->savePath );
		}
		chmod($upload->savePath,0777);		
		if(!$upload->upload()) {// 上传错误提示错误信息
			if($edit=='insert'){
				return 0;
				exit;
			}
		}else{
			import('ORG.Util.Image.ThinkImage');
			$info = $upload->getUploadFileInfo();
			foreach ($info as $key => $value) {
				if($value['key']=="image"){
					$image=$upload->savePath.$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image); 
					$img->thumb(180, 200,THINKIMAGE_THUMB_FIXED)->save($image);	
				}
				if($value['key']=="image1"){
					$image1=$upload->savePath.$value['savename'];
					$thumb1=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image1); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb1);
				}
				if($value['key']=="image2"){
					$image2=$upload->savePath.$value['savename'];
					$thumb2=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image2); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb2);
				}
				if($value['key']=="image3"){
					$image3=$upload->savePath.$value['savename'];
					$thumb3=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image3); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb3);
				}
				if($value['key']=="image4"){
					$image4=$upload->savePath.$value['savename'];
					$thumb4=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image4); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb4);
				}
				if($value['key']=="image5"){
					$image5=$upload->savePath.$value['savename'];
					$thumb5=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image5); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb5);
				}
				if($value['key']=="image6"){
					$image6=$upload->savePath.$value['savename'];
					$thumb6=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image6); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb6);
				}
				if($value['key']=="image7"){
					$image7=$upload->savePath.$value['savename'];
					$thumb7=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image7); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb7);
				}
				if($value['key']=="image8"){
					$image8=$upload->savePath.$value['savename'];
					$thumb8=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image8); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb8);
				}
				if($value['key']=="image9"){
					$image9=$upload->savePath.$value['savename'];
					$thumb9=$upload->savePath."thumb_".$value['savename'];
					$img = new ThinkImage(THINKIMAGE_GD, $image9); 
					$img->thumb(137, 158,THINKIMAGE_THUMB_FIXED)->save($thumb9);
				}			
			}

			return array('image'=>$image,'image1'=>$image1,'image2'=>$image2,'image3'=>$image3,'image4'=>$image4,'image5'=>$image5,'image6'=>$image6,'image7'=>$image7,'image8'=>$image8,'image9'=>$image9,'thumb1'=>$thumb1,'thumb2'=>$thumb2,'thumb3'=>$thumb3,'thumb4'=>$thumb4,'thumb5'=>$thumb5,'thumb6'=>$thumb6,'thumb7'=>$thumb7,'thumb8'=>$thumb8,'thumb9'=>$thumb9);		
		}
	}

	function musicUpload($edit='insert',$folder='Music'){
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();// 实例化上传类
		//$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->allowExts  = array('mp3');// 设置附件上传类型
		$upload->savePath =  'Public/Uploads/'.$folder."/".date('Ymd',time()).'/';// 设置附件上传目录
		if(!is_dir('Public/Uploads/'.$folder)){
			mkdir('Public/Uploads/'.$folder);
		}
		if(!is_dir($upload->savePath )){
			mkdir($upload->savePath );
		}
		chmod($upload->savePath,0777);		
		if(!$upload->upload()) {// 上传错误提示错误信息
			if($edit=='insert'){
				return 0;
				exit;
			}
		}else{
			$info = $upload->getUploadFileInfo();
			$filename = $upload->savePath.$info[0]['savename'];
			//import('ORG.Util.Image.ThinkImage');
			//$img = new ThinkImage(THINKIMAGE_GD, $filename); 
			//$img->thumb(128, 128,THINKIMAGE_THUMB_FILLED)->save($filename);
			return $filename;		
		}
	}
	function catupload($edit='insert',$folder){
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();// 实例化上传类
		//$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->savePath =  'Public/Uploads/'.$folder."/".date('Ymd',time()).'/';// 设置附件上传目录
		if(!is_dir('Public/Uploads/'.$folder)){
			mkdir('Public/Uploads/'.$folder);
		}
		if(!is_dir($upload->savePath )){
			mkdir($upload->savePath );
		}
		chmod($upload->savePath,0777);		
		if(!$upload->upload()) {// 上传错误提示错误信息
			if($edit=='insert'){
				
				return 0;
				exit;
			}
		}else{
			$info = $upload->getUploadFileInfo();
			$filename = $upload->savePath.$info[0]['savename'];
			// $thumb=$upload->savePath."thumb_".$info[0]['savename'];
			import('ORG.Util.Image.ThinkImage');
			$img = new ThinkImage(THINKIMAGE_GD, $filename); 
			$img->thumb(200, 188,THINKIMAGE_THUMB_FIXED)->save($filename);
			return $filename;		
		}
	}

	function tempimageupload($edit='insert',$folder){
		import('ORG.Net.UploadFile');
		$upload = new UploadFile();// 实例化上传类
		//$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
		$upload->savePath =  'Public/Uploads/'.$folder."/".date('Ymd',time()).'/';// 设置附件上传目录
		if(!is_dir('Public/Uploads/'.$folder)){
			mkdir('Public/Uploads/'.$folder);
		}
		if(!is_dir($upload->savePath )){
			mkdir($upload->savePath );
		}
		chmod($upload->savePath,0777);		
		if(!$upload->upload()) {// 上传错误提示错误信息
			if($edit=='insert'){
				
				return 0;
				exit;
			}
		}else{
			$info = $upload->getUploadFileInfo();
			$filename = $upload->savePath.$info[0]['savename'];
			// $thumb=$upload->savePath."thumb_".$info[0]['savename'];
			import('ORG.Util.Image.ThinkImage');
			$img = new ThinkImage(THINKIMAGE_GD, $filename); 
			$img->thumb(180, 200,THINKIMAGE_THUMB_FIXED)->save($filename);
			return $filename;		
		}
	}

	function guid() 
	{

		if (function_exists('com_create_guid'))
		    {

		        $uuid =  com_create_guid();

		        $uuid = str_replace("{", "", $uuid);

				$uuid = str_replace("}", "", $uuid);

				return strtolower($uuid);
		    }else{
		        mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
		        $charid = strtoupper(md5(uniqid(rand(), true)));
		        $hyphen = chr(45);// "-"
		        $uuid =  substr($charid, 0, 8).$hyphen
		                .substr($charid, 8, 4).$hyphen
		                .substr($charid,12, 4).$hyphen
		                .substr($charid,16, 4).$hyphen
		                .substr($charid,20,12);
		        return strtolower($uuid);
	    }
	}